package recursion






func Subs(str string) []string {
	ans := []string{}
	var fn = func(substr string) {
		ans = append(ans, substr)
	}
	Process1(str, 0, "", fn)
	return ans
}

func Process1(str string, index int,  path string, fn func(string)){
	if index == len(str) {
		fn(path)
		return
	}
	no := path
	yes := path + string(str[index])
	Process1(str, index+1, yes, fn)
	Process1(str, index+1, no, fn)
}

func SubsWithoutRepeat(str string) []string {
	ans := []string{}
	set := map[string]bool{}
	var fn = func(substr string) {
		if !set[substr] {
			ans = append(ans, substr)
			set[substr] = true
		}
	}
	Process2(str, 0, "", fn)
	return ans
}

func Process2(str string, index int,  path string, fn func(string)){
	if index == len(str) {
		fn(path)
		return
	}
	no := path
	yes := path + string(str[index])
	Process1(str, index+1, yes, fn)
	Process1(str, index+1, no, fn)
}